<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var person = {
        personName:"zhangsan",
        age:20,
        sayHello:function(){
            console.log("hello");
        }
    }

    /*增删查改-->查*/
    //第一种写法，最常用的写法-->对象.属性名、对象.方法名()
    console.log(person.age)
    person.sayHello();//访问方法必须加括号
    //第二中写法 对象["属性名"]
    console.log(person["personName"]);//中括号、引号不可缺
    person["sayHello"]();//方法的括号加到最后
    
    /**区别：
     * 对象[变量] 
     * 中括号中可以放变量
    */
    var attr = "age";
    console.log(person[attr]);
    //访问不存在的属性，打印undefined
    console.log(person.hobby);

    /*增删查改-->增*/
    person.hobby = ["swimming","football"];
    console.log(person);
    //添加一个weight属性
    person["weight"] = "50kg";
    console.log(person);

    /*增删查改-->改*/
    person.age = 30;
    person["weight"] = "48kg";
    console.log(person);

    /*增删查改-->删*/
    delete person.weight;
    console.log(person.weight);//undefined


</script>
</html>